package com.example.utils;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@NoArgsConstructor
public class Pagination<T> {
    public static final String ASC = "asc";
    public static final String DESC = "desc";

    protected int pageNo = 1;
    protected int pageSize = 10;

    protected String orderBy = "id";
    protected String order = "desc";
    protected long count = -1L;

    protected List<T> result = new ArrayList<>();
    public JSONObject param = JSONUtil.createObj();

    @JsonIgnore
    private int start;

    public int getStart() {
        return (this.pageNo - 1) * this.pageSize;
    }
}
